package threaddemo16;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2022-08-07
 * Time: 17:35
 */
/*
消费者类(Foodie)：继承Thread类，重写run()方法，设置线程任务
1.构造方法中接收一个阻塞队列对象
2.在run方法中循环获取阻塞队列中的包子
3.打印获取结果
*/
public class Foodie extends Thread{
    private ArrayBlockingQueue<String> aq;
    public Foodie(ArrayBlockingQueue<String> aq) {
        this.aq=aq;
    }
    
    @Override
    public void run() {
        while (true) {
            try {
                String ret=aq.take();
                System.out.println("吃货吃了一个"+ret);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
